/**
 * 遮罩层控件
 * op:开关
 * z-index:层级，默认99
 */
$.showAddBg = function(op, zIndex, isLoading){
    if (op) {
    	if($("#BG_SHADE_DIV").length==0){
        	$("body").append("<div id=\"BG_SHADE_DIV\"></div>");
        	$(window).resize(function(){
				$("#BG_SHADE_DIV").css({
		            "height": $(window).height() + "px",
		            "width": $(window).width() + "px"
		       });
			});
    	} 
        $("#BG_SHADE_DIV").css({
            "height": $(document).height() + "px",
            "width": $(document).width() + "px",
            "zIndex": 99
        }).show();
        if (zIndex != null) {
            $("#BG_SHADE_DIV").css("zIndex", zIndex);
        }
        if(isLoading) {
        	$("#BG_SHADE_DIV").html("<div class=\"loading\">&nbsp</div>");
        }
    }
    else {
        $("#BG_SHADE_DIV").hide().empty();
    }
};

/**
 * 显示提示卡片
 * msg	提示的内容那个
 * btn	按钮的显示内容
 * fun	点击按钮额外触发的动作
 */
$.showAlert = function(msg, btn, fun){
	$.showAddBg(true, 99998);
	if($("#FLOAT_ALERT_DIV").length!=0) {
		$("#FLOAT_ALERT_DIV").remove();
	}
	$("body").append("<div id=\"FLOAT_ALERT_DIV\" class=\"divAlertCard\">"
			+"<span class=\"btn\">"+btn+"</span>"
			+"<span class=\"pin\"></span>"
			+"<span class=\"text\">"+msg+"</span></div>");
	var self = $("#FLOAT_ALERT_DIV");
	self.slideDown("fast").find("span.btn").bind("click", function(){
		self.slideUp("fast");
		$.showAddBg(false);
		if($.isFunction(fun)) {
			fun();
		}
	});
};

$.changeAlert = function(msg){
	if($("#FLOAT_ALERT_DIV").length!=0) {
		$("#FLOAT_ALERT_DIV").find("span.text").html(msg);
	}
};

$.hideAlert = function(){
	$.showAddBg(false);
	if($("#FLOAT_ALERT_DIV").length!=0) {
		$("#FLOAT_ALERT_DIV").slideUp("fast", function(){
			$(this).remove();
		});
	}
};

/**
 * 分页控件
 * funName:分页点击后调用的方法，参数必须为当前跳转页面
 * pageIndex: 当前页码，从1开始
 * itemSize: 列表总条数
 */
$.fn.initPagination = function(funName, pageIndex, itemSize) {
    var PageHtml = "";
    var TotalPageNum = Math.ceil(parseInt(itemSize, 10)/10);
    var CurrentPageNum = pageIndex;
    if (TotalPageNum <= 10) {
    	for(var i=1; i<=TotalPageNum; i++) {
        	if(i==CurrentPageNum) {
            	PageHtml += "<a class=\"on\" onclick=\"" + funName+"("+i+");\">" + i + "</a>";
        	} else {
            	PageHtml += "<a onclick=\"" + funName+"("+i+");\">" + i + "</a>";
        	}
        }
    } else {
    	if(CurrentPageNum<=4){
    		for (var i = 1; i < 9; i++) {
            	if(i==CurrentPageNum) {
	            	PageHtml += "<a class=\"on\" onclick=\"" + funName+"("+i+");\">" + i + "</a>";
	        	} else {
	            	PageHtml += "<a onclick=\"" + funName+"("+i+");\">" + i + "</a>";
	        	}
            }
            PageHtml += "<a onclick=\"" + funName+"("+(CurrentPageNum+10>TotalPageNum?TotalPageNum:CurrentPageNum+10)+");\">...</a>";
    		PageHtml += "<a onclick=\"" + funName+"("+TotalPageNum+");\">"+TotalPageNum+"</a>";
    	} else if(TotalPageNum-CurrentPageNum<=7) {
    		PageHtml += "<a onclick=\"" + funName+"(1);\">1</a>";
    		PageHtml += "<a onclick=\"" + funName+"("+(CurrentPageNum-10<1?1:CurrentPageNum-10)+");\">...</a>";
    		for (var i = (TotalPageNum-8); i <= TotalPageNum; i++) {
            	if(i==CurrentPageNum) {
	            	PageHtml += "<a class=\"on\" onclick=\"" + funName+"("+i+");\">" + i + "</a>";
	        	} else {
	            	PageHtml += "<a onclick=\"" + funName+"("+i+");\">" + i + "</a>";
	        	}
            }
    	} else {
    		PageHtml += "<a onclick=\"" + funName+"(1);\">1</a>";
    		PageHtml += "<a onclick=\"" + funName+"("+(CurrentPageNum-10<1?1:CurrentPageNum-10)+");\">...</a>";
    		for(var i=CurrentPageNum-2; i<=CurrentPageNum+5; i++){
    			if(i==CurrentPageNum) {
	            	PageHtml += "<a class=\"on\" onclick=\"" + funName+"("+i+");\">" + i + "</a>";
	        	} else {
	            	PageHtml += "<a onclick=\"" + funName+"("+i+");\">" + i + "</a>";
	        	}
    		}
    		PageHtml += "<a onclick=\"" + funName+"("+(CurrentPageNum+10>TotalPageNum?TotalPageNum:CurrentPageNum+10)+");\">...</a>";
    		PageHtml += "<a onclick=\"" + funName+"("+TotalPageNum+");\">"+TotalPageNum+"</a>";
    	}
    	PageHtml +="<span><a style=\"margin-right:0px;\">GO</a><input id=\"ipt_skip_val\" type=\"text\" onkeyup=\"value=this.value.replace(/\D+/g,'');\" /></span>";
    }
    $(this).html(PageHtml);
};

$.formatObj = function(obj){
	for (var key in obj) {
		if(obj[key]==null || obj[key]=="null") {
			obj[key]="";
		}
	};
	return obj;
};






























